<?php
if(!function_exists("create_ir_states_table")){
	function create_ir_states_table(){
		global $wpdb;
		$update_year = MASHAGHEL_CONFIGS["ir_states_db"]["states_year"];
		$table_name      = $wpdb->prefix . MASHAGHEL_CONFIGS["ir_states_db"]["table_name"];
		$charset_collate = $wpdb->get_charset_collate();

		$query = "CREATE TABLE IF NOT EXISTS $table_name
		(
  	id int auto_increment,
	year int null,
	state_code int null,
	state tinytext not null,
	city_code tinytext not null,
	district_code int null,
	district tinytext null,
	city_village_code int null,
	constraint table_name_pk
		primary key (id)
) $charset_collate;

		";
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
		dbDelta( $query );
$query = "select year from $table_name";
$year = $wpdb->get_var($query);
console_log($year);
if(intval($year)!= $update_year){
	require_once(MASHAGHEL_DIR."database/ir_states_insert_query.php");
	console_log(MASHAGHEL_DIR."database/ir_states_insert_query.php");
	$query = query1397($table_name);
//	$query = $wpdb->prepare($query);
	$wpdb->query($query);
}
	}
}
function get_ir_states(){
	global $wpdb;
	$update_year = MASHAGHEL_CONFIGS["ir_states_db"]["states_year"];
	$table_name      = $wpdb->prefix . MASHAGHEL_CONFIGS["ir_states_db"]["table_name"];
	$query = "select distinct state_code,state from $table_name where year =
(select max(year) from $table_name ) order by state ;";
	$results = $wpdb->get_results($query);
}